package com.qc.bus.controller;


import com.baomidou.mybatisplus.extension.api.ApiController;
import com.qc.bus.entity.BusProvider;
import com.qc.bus.service.BusProviderService;
import com.qc.bus.vo.ProviderVo;
import com.qc.sys.common.Constant;
import com.qc.sys.common.ResultObj;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * (BusProvider)表控制层
 *
 * @author AltmanQccc
 * @since 2020-09-08 23:11:01
 */
@RestController
@RequestMapping("provider")
public class BusProviderController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private BusProviderService busProviderService;

    @Resource
    private BusProviderService providerService;
    /**
     * 查询并展示数据
     * */
    @GetMapping("loadAllProvider")
    public Object loadAllProvider(ProviderVo providerVo){
        return this.busProviderService.queryAllProvider(providerVo);
    }

    /**
     * 添加客户
     * */
    @PostMapping("addProvider")
    public ResultObj addProvider(BusProvider provider){
        try {
            provider.setAvailable(Constant.USER_AVAILABLE_TRUE);
            this.busProviderService.InsertProvider(provider);
            return ResultObj.ADD_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultObj.ADD_ERROR;
        }
    }

    /**
     * 修改客户
     * */
    @PostMapping("updateProvider")
    public ResultObj updateProvider(BusProvider provider){
        try {
            this.busProviderService.UpdateProvider(provider);
            return ResultObj.UPDATE_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultObj.UPDATE_ERROR;
        }
    }

    /**
     * 删除客户
     * */
    @PostMapping("deleteProvider")
    public ResultObj deleteProvider(Integer id){
        try {
            this.busProviderService.removeById(id);
            return ResultObj.DELETE_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultObj.DELETE_ERROR;
        }
    }

    /**
     * 批量删除
     * */
    @PostMapping("batchDeleteProvider")
    public ResultObj batchDeleteProvider(Integer[] ids){
        return this.busProviderService.batchDeleteProvider(ids);
    }

    /**
     * 查询可用的供应商
     * */
    @GetMapping("getAllAvailableProvider")
    public Object getAllAvailableProvider(){
        return this.busProviderService.queryAllAvailableProvider();
    }
}